package com.example.android.google.apis;

import java.util.ArrayList;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

public class HelloItemizedOverlay extends ItemizedOverlay<OverlayItem> {
	

	private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
	Context mContext;

	public HelloItemizedOverlay(Drawable defaultMarker) {
		super(boundCenterBottom(defaultMarker));
		// TODO Auto-generated constructor stub
	}

	public HelloItemizedOverlay(Drawable defaultMarker, Context context) {
		  //super(defaultMarker);
		super(boundCenterBottom(defaultMarker));
		  mContext = context;
	}
	
	@Override
	protected OverlayItem createItem(int i) {
		// TODO Auto-generated method stub
		return mOverlays.get(i);
	}

	@Override
	public int size() {
		// TODO Auto-generated method stub
		return mOverlays.size();
	}
	
	public void addOverlay(OverlayItem overlay) {
	    mOverlays.add(overlay);
	    populate();
	}
	
	@Override
	public boolean onTap(int index) {
		/*OverlayItem item = mOverlays.get(index);
		AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
		dialog.setTitle(item.getTitle());
		dialog.setMessage(item.getSnippet());
		dialog.show();
		return true;  /* ESSA PARTE TAMBEM FUNCIONA*/
		
		OverlayItem item = mOverlays.get(index);
		Intent intent = new Intent(mContext , HelloComments.class);
		intent.putExtra("msg", item.getTitle());
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
        mContext.startActivity(intent);
        
		return true;
	}
	
	
	
	
}
